#pragma once
#include "noncopyable.h"
#include <functional>
#include <mutex>
#include <condition_variable>
#include "Thread.h"
#include <string>
//作用：创建eventloop和thread绑定的对象，one loop per thread
class EventLoop;

class EventLoopThread : noncopyable {
    public:
        using ThreadInitCallback = std::function<void(EventLoop *)>; //线程初始化时，首先会调用这个函数

        EventLoopThread(const ThreadInitCallback &cb = ThreadInitCallback(),
            const std::string& name = std::string());
        ~EventLoopThread();

        EventLoop* startLoop();

    private:
        void threadFunc();

        EventLoop *loop_;
        bool exiting_;
        Thread thread_;
        std::mutex mutex_;
        std::condition_variable cond_;

        ThreadInitCallback callback_;

};


